var app = getApp();
Page({
  data: {
	cdnUrl: '',
    isWxapp: true,
    userInfo: {
      id: 0,
      avatar: '/assets/images/avatar.png',
      nickname: '用户昵称',
      balance: 0,
      score: 0,
      level: 0
    },
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#FFFFFF',
		show: true,
		animated: false,
		back: true,
		title: "积分明细",
		
		/* 筛选 */
		status: 0,
		status_text: '全部',
		scoreList:[],
    array: ['全部', '支出', '收入']
  },
	scoreList: function(status){
		var that = this;
		app.request('/addons/cms/wxapp.shop/scoreList', {status: status}, function (data, ret) {
		  that.setData({
		    scoreList: data,
		  });
		}, function (data, ret) {
			console.log(ret);
		  app.error('服务器错误');
		});
	},
  onLoad: function () {
    var that = this;
    that.setData({
    	cdnUrl: app.cdnUrl,
    });
  },
  onShow: function (e) {
    var that = this;
		that.scoreList(that.data.status);
    if (app.globalData.userInfo) {
      that.setData({ 
        userInfo: app.globalData.userInfo,
      });
    }else{
			app.showLoginModal(e);
		}
  },
  login: function () {
    var that = this;
    wx.getUserProfile({
      lang:'zh',
      desc:'授权用户信息',
      success:function(res){
        console.log(res)
        app.login(res.userInfo,function () {
          that.setData({ 
            userInfo: app.globalData.userInfo, 
            isWxapp: that.isWxapp()
          });
        });
      },
      fail:function(e){
        app.info(JSON.stringify(e));
      }
    })


  },
  showTips: function (event) {
    var tips = {
      balance: '余额',
      score: '积分',
      level: '等级通过官网活跃进行升级',
    };
    var type = event.currentTarget.dataset.type;
    var content = tips[type];
    wx.showModal({
      title: '温馨提示',
      content: content,
      showCancel: false
    });
  },
  //点击头像上传
  bindPickerChange: function(e){
    console.log(e);
    var that = this;
    var status = e.detail.value;
    that.setData({
      status: status,
      status_text: that.data.array[status],
    })
    that.scoreList(status);
  }
  
})
